package com.vjmobi.test.vo;

import java.util.Date;

import com.vjmobi.test.util.ResultCode;

public class ApiResult<T> {
	private Date time;
	private String code;
	private String msg;
	private T data;
	
	public static <T>ApiResult<T> success(String msg) {
		return ApiResult.build(ResultCode.SUCCESS, msg, null);
	}
	public static <T>ApiResult<T> success(String msg,T data) {
		return ApiResult.build(ResultCode.SUCCESS, msg, data);
	}
	public static <T>ApiResult<T> success(T data) {
		return ApiResult.build(ResultCode.SUCCESS, "SUCCESS", data);
	}
	
	public static <T>ApiResult<T> error(String msg) {
		return ApiResult.build(ResultCode.ERROR, msg, null);
	}
	
	private static <T>ApiResult<T> build(String code,String msg,T data){
		ApiResult<T> result = new ApiResult<>();
		result.time = new Date();
		result.code = code;
		result.msg = msg;
		result.data = data;
		return result;
	}
	
	public Date getTime() {
		return time;
	}
	public void setTime(Date time) {
		this.time = time;
	}
	public String getCode() {
		return code;
	}
	public void setCode(String code) {
		this.code = code;
	}
	public String getMsg() {
		return msg;
	}
	public void setMsg(String msg) {
		this.msg = msg;
	}
	public T getData() {
		return data;
	}
	public void setData(T data) {
		this.data = data;
	}
	@Override
	public String toString() {
		return "ApiResult [time=" + time + ", code=" + code + ", msg=" + msg + ", data=" + data + "]";
	}
}
